<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/finishedOrder.css?v=2020072201">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("订单确认");

        var app = new Vue({
            el: '#container',
            data: {
                number: 0,
                singlePrice: $("input[name=salePrice]").val(),
                sizeList: [],
                sizeDetailList: [],
                sizeNum: [],
                num:0,
                submit:0
            },
            methods: {
				createOrder: function() {

                    var productId = "{$product.product_id}";
//                    var salePrice = $("input[name=salePrice]").val();
//                    var size = $("input[name=size]").val();
                    var number = app.number;
                    var deliveryType = $("select[name=deliveryType]").val();
                    var receiveName = $("input[name=receiveName]").val();
                    var receiveMobile = $("input[name=receiveMobile]").val();
                    var receiveAddress = $("input[name=receiveAddress]").val();
                    var customerName = $("input[name=customerName]").val();
                    var patientName = $("input[name=patientName]").val();
                    var doctorName = $("input[name=doctorName]").val();
                    var hospitalName = $("input[name=hospitalName]").val();
                    var note = $("input[name=note]").val();
                    var needInvoice = $("select[name=needInvoice]").val();
                    var invoiceName = $("input[name=invoiceName]").val();
                    var invoiceNumber = $("input[name=invoiceNumber]").val();
                    var invoiceDetail = $("input[name=invoiceDetail]").val();
                    var needPatient = $("input[name=needPatient]").val();

                    var data = {};

//                    if(number == 0) {
//                        alert("请选择规格");
//                        return false;
//                    }

                    if (isNullOrEmpty(patientName)) {
                        alert("请填写患者姓名");
                        return false;
                    }
//
                    if (isNullOrEmpty(doctorName)) {
                        alert("请填写医生姓名");
                        return false;
                    }

                    if (isNullOrEmpty(hospitalName)) {
                        alert("请填写医院名称");
                        return false;
                    }

                    if(isNullOrEmpty(receiveName)) {
                        alert("请填写收件人姓名");
                        return false;
                    }

                    if(isNullOrEmpty(deliveryType)) {
                        alert("请选择提货方式");
                        return false;
                    }

                    if(deliveryType == "快递"){
                        if(isNullOrEmpty(receiveAddress)) {
                            alert("请填写收件人地址");
                            return false;
                        }
                    }

                    if(isNullOrEmpty(receiveMobile)) {
                        alert("请填写收件人电话");
                        return false;
                    }

                    if(!checkPhone(receiveMobile)) {
                        alert("手机号位数不对");
                        return false;
                    }

                    if(needInvoice == 1) {
                        if(isNullOrEmpty(invoiceName)) {
                            alert("请填写发票抬头");
                            return false;
                        }
                        if(isNullOrEmpty(invoiceNumber)) {
                            alert("请填写纳税人识别号");
                            return false;
                        }
                    }
//                    if(needInvoice != -1) {
//                        if(isNullOrEmpty(invoiceDetail)) {
//                            alert("请填写发票明细");
//                            return false;
//                        }
//                    }

                    data.productId = productId;
                    data.deliveryType = deliveryType;
                    data.receiveName = receiveName;
                    data.receiveMobile = receiveMobile;
                    data.receiveAddress = receiveAddress;
                    data.customerName = customerName;
                    data.patientName = patientName;
//                    data.patientSex = patientSex;
//                    data.patientAge = patientAge;
                    data.doctorName = doctorName;
                    data.hospitalName = hospitalName;
                    data.note = note;
                    data.needInvoice = needInvoice;
                    data.invoiceName = invoiceName;
                    data.invoiceNumber = invoiceNumber;
                    data.invoiceDetail = invoiceDetail;
                    data.agentName = agentName;

                    if(confirm("请确认是否提交订单？")){
                        $.ajax({
                            url:"/wechat/finishedProduct/createOrder",
                            type:"post",
                            data:data,
                            dataType:"JSON",
                            beforeSend:function(){
                                $("#loadingToast").show();
                                $("#submitBtn").hide();
                            },
                            complete:function(){
                                $('#loadingToast').hide();
                            },
                            success:function(data){
                                if(data.code != 200) {
                                    alert(data.msg);
                                    window.location.href = "/wechat/finishedProduct/orderList";
                                }else{
                                    window.location.href = "/wechat/finishedProduct/orderList";
                                }

                            },
                            error:function(data){
                                window.location.href = "/wechat/finishedProduct/orderList";
                            }
                        })
                    }else{
                        return;
                    }


                }
            }
        })


        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("select[name=needInvoice]").change(function() {
            if($(this).val() == 1) {
                $(".item.invoice").show();
            } else {
                $(".item.invoice").hide();
            }
            if($(this).val() == -1) {
                $(".item.invoiceDetail").hide();
            } else {
                $(".item.invoiceDetail").show();
            }
        });

        $("select[name=deliveryType]").change(function() {
            if($(this).val() == "自提") {
                $(".item.receiveAddress").hide();
            } else {
                $(".item.receiveAddress").show();
            }
        });

        $("img.icon-up").click(function() {

            $(this).hide();
            $("img.icon-down").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();

        });

        $("img.icon-down").click(function() {

            $(this).hide();
            $("img.icon-up").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();
        });

    })

</script>

<div class="container" id="container">
	<input type="hidden" name="couponCode" value="{$coupon.coupon_code}" />
	<div class="product-detail">
		<img class="product-img" src="{$product.image_url}" alt="product">
		<div class="detail-info">
			<p class="product-price" style="color: #de7d74" id="productPrice">￥{$coupon.price}</p>
			<p class="product-name" style="font-weight: bold; color: #45a1de">{$product.product_name}</p>
			<p class="product-size" style="color: #45a1de">【{$coupon.size}】码</p>
			<p class="buy-time">订购日期：{:date("Y-m-d")}</p>
		</div>
	</div>
	<div class="patient-info agent">
		<div class="item">
			<span>患者姓名</span>
			<input type="text" name="patientName" placeholder="请填写患者姓名">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<input type="hidden" name="needPatient">
	</div>
	<div class="doctor-info agent">
        <div class="item">
            <span>医生</span>
            <input type="text" name="doctorName" value="{$coupon.doctor_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item">
            <span>医院</span>
            <input type="text" name="hospitalName" value="{$coupon.hospital_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
    </div>

	<div class="product-need" style="margin-bottom: 0">
		<div class="item">
			<span>是否开发票</span>
			<input type="text" value="不开发票" name="needInvoice" readonly placeholder="">
			<select name="needInvoice" class="invoice-choose">
				<option value="-1">不开发票</option>
				<option value="1">公司发票</option>
				<option value="2">个人发票</option>
			</select>
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice" style="display: none;">
			<span>发票抬头</span>
			<input name="invoiceName" type="text" placeholder="请填写发票抬头">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice" style="display: none;">
			<span>纳税人识别号</span>
			<input name="invoiceNumber" type="text" placeholder="请填纳税人识别号">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoiceDetail" style="display: none;">
			<span>发票明细</span>
			<input name="invoiceDetail" type="text" placeholder="请填写发票明细">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="address-info" style="margin-bottom: 1rem">
		<div class="item">
			<span>收件人姓名</span>
			<input type="text" name="receiveName" placeholder="请填写收件人姓名">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item">
			<span>收件人电话</span>
			<input type="text" name="receiveMobile" placeholder="请填写收件人电话">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item receiveAddress">
			<span>收件地址</span>
			<input type="text" name="receiveAddress" placeholder="请填写收件地址">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item">
			<span>留言备注</span>
			<input type="text" name="note" placeholder="请编辑备注信息">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="order-operation">
		<p style="margin-left: 20%;width: 40%">共<a style="color: #e97a15"> {$coupon.number} </a>件,合计：<span>￥{$coupon.price}</span> </p>
		<button id="submitBtn" class="submit-order" v-on:click="createOrder">提交订单</button>
	</div>
</div>
<include file="./Template/footer.html" />